﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Kugar.Core.Configuration;
using Kugar.Core.ExtMethod;
using Kugar.Tool.DataSync.Client.BLL;
using Microsoft.Owin.Hosting;

namespace Kugar.Tool.DataSync.Client
{
    partial class DataSyncService : ServiceBase
    {
        private IDisposable _webApp = null;

        public DataSyncService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。

            int port = CustomConfigManager.Default.AppSettings.GetValueByName("HttpPort", "9090").ToInt();

            _webApp = WebApp.Start<Startup>(new StartOptions()
            {
                Port = port
            });
            
            Console.WriteLine("已开始监听");
            
        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。

            _webApp.Dispose();
            WebBLL.Plugin.Close();
        }
    }
}
